package xdu.lz.stage2_design_pattern.chapter6_immutable_pattern;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

//注意虽然这样写了，但是是可变的，因为返回的list会被外部修改
//解决：1)返回不可修改的list 2)或者返回一个list的克隆
public final class ImmutableTest {
    private final int age;
    private final String name;
    private final List<String> list;

    public ImmutableTest(int age, String name) {
        this.age = age;
        this.name = name;
        this.list = new ArrayList<>();
    }

    public int getAge() {
        return age;
    }

    public String getName() {
        return name;
    }

    public List<String> getList() {
//        return list;
        return Collections.unmodifiableList(list);

    }
}
